//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.member;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.MemberInfoDao;
import com.aidong.model.wills.MemberInfo;
import com.aidong.web.controller.BaseController;
import java.util.Calendar;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"memberInfoEdit"})
public class MemberInfoEditController extends BaseController {
    @Resource
    MemberInfoDao memberInfoDao;

    public MemberInfoEditController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return new ModelAndView("member/infoedit/list");
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "cardCode",required = false) String cardCode, @RequestParam(value = "memberCode",required = false) String memberCode, @RequestParam(value = "name",required = false) String name, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "shopCode", shopCode);
        cd.eq("cardCode", cardCode);
        cd.eq("memberCode", memberCode);
        if(!this.chkNull(name)) {
            ConditionMap cal = new ConditionMap(1);
            cal.like("chName", "%" + name + "%");
            cal.like("enName", "%" + name + "%");
            cal.like("idNumber", "%" + name + "%");
            cal.like("mobile", "%" + name + "%");
            cd.addSub(cal);
        }

        Calendar cal1 = Calendar.getInstance();
        cal1.add(5, -3);
        cal1.set(11, 5);
        cd.gt("createTime", cal1.getTime());
        this.memberInfoDao.queryPageList(pg, cd, (new OrderSet()).desc("createTime"));
        ModelAndView mv = new ModelAndView("member/infoedit/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"edit"})
    public ModelAndView edit(@RequestParam("code") String code) {
        MemberInfo member = this.memberInfoDao.getById(code);
        if(member == null) {
            return this.showAlert("没有这个会员");
        } else if(System.currentTimeMillis() - member.getCreateTime().getTime() > 345600000L) {
            return this.showAlert("只能补充新会员资料,老会员请去审批流提交申请");
        } else {
            ModelAndView mv = new ModelAndView("member/infoedit/edit");
            mv.addObject("member", member);
            mv.addObject("gender", this.getTypeList("gender"));
            mv.addObject("idType", this.getTypeList("idType"));
            mv.addObject("_oper", "edit");
            return mv;
        }
    }

    @RequestMapping({"_edit"})
    @ResponseBody
    public String _edit(@ModelAttribute("member") MemberInfo member) {
        if(this.chkNull(member.getMemberCode())) {
            return this.getResult(false, "没有这个会员");
        } else if(this.chkNull(member.getChName())) {
            return this.getResult(false, "请输入会员姓名");
        } else if(this.chkNull(member.getGender())) {
            return this.getResult(false, "请输入性别");
        } else if(this.chkNull(member.getIdType())) {
            return this.getResult(false, "请输入证件类型");
        } else if(this.chkNull(member.getIdNumber())) {
            return this.getResult(false, "请输入证件号码");
        } else if(this.chkNull(member.getMobile())) {
            return this.getResult(false, "请输入手机号");
        } else {
            MemberInfo member1 = this.memberInfoDao.getById(member.getMemberCode());
            if(member1 == null) {
                return this.getResult(false, "没有这个会员");
            } else {
                member1.setChName(member.getChName());
                member1.setEnName(member.getEnName());
                member1.setGender(member.getGender());
                member1.setIdType(member.getIdType());
                member1.setIdNumber(member.getIdNumber());
                member1.setMobile(member.getMobile());
                member1.setPhone(member.getPhone());
                member1.setBirthday(member.getBirthday());
                member1.setCountry(member.getCountry());
                member1.setEmail(member.getEmail());
                member1.setAddress(member.getAddress());
                member1.setNote(member.getNote());
                if(!this.chkNull(member.getMemberPhoto())) {
                    member1.setMemberPhoto(member.getMemberPhoto());
                }

                if(!this.chkNull(member.getIdCardPhoto())) {
                    member1.setIdCardPhoto(member.getIdCardPhoto());
                }

                member1.setUpdateTime(new Date());

                try {
                    this.memberInfoDao.update(member1);
                    this.addUserLog("新会员资料补充", "编号:" + member1.getMemberCode() + ",名称:" + member1.getChName());
                } catch (Exception var4) {
                    this.log.error("edit member", var4);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            }
        }
    }
}
